package com.itany.corejava.code10_异常;

/**
 * @author MissChen
 * @version 1.0
 * @date 2023 年11月23日 16:00
 */
public class Test08_异常 {
    public static void main(String[] args) throws UserExistException {
        UserService userService=new UserService();

        try {
            userService.register("admin","123456");
        } catch (UserExistException e) {
            System.out.println(e.getMessage());
        }
        System.out.println(111);


    }
}
class UserDao{
    public void insertUser(String username,String password) throws UserExistException {

        //用户已经存在
        if("admin".equals(username)){
            throw new UserExistException("该用户已经存在");

        }
        System.out.println("注册成功");

    }
}

class UserService{
    UserDao userDao=new UserDao();
    public void register(String username,String password) throws UserExistException {
        userDao.insertUser(username,password);
    }
}